﻿<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="Summary.aspx.cs" Inherits="CRMWeb.Pages.Summary" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <input type="hidden" id="hdnContactId" />
    <input type="hidden" id="hdnApp_Id" />
    <input type="hidden" id="hdnIncomeType" />
    <table class="easyui-datagrid" title="PARTY DETAILS (Borrower and other parties)" style="width: auto;" autorowheight="true"
        id="dgSummary" data-options="url: '/WebServices/AM/Summary.ashx?LoanID='+getQuerystring('LoanID', ''),pageSize:10"
        rownumbers="true" fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="Title" width="10"></th>
                <th field="FirstName" width="40">Party</th>
                <th field="Mobile" width="40">Mobile</th>
                <th field="HomePhone" width="30">Phone</th>
                <th field="Email" width="50">Email Address</th>
                <th field="DateBirth" width="30" data-options="formatter:formatDateBirth">DOB</th>
                <th field="Street" width="60">Address</th>
            </tr>
        </thead>
    </table>
    <div id="tabSummary" class="easyui-tabs" style="width: auto; height: auto;">
        <div id="pnlParties" title="Parties" runat="server" data-options="href:'/Pages/AM/Parties.aspx'" style="padding: 10px; width: auto; height: auto;">
        </div>
        <div id="pnlContract" title="Setup" data-options="href:'/Pages/AM/Contract.aspx'" style="padding: 10px; width: auto; height: auto;">
        </div>
        <div id="pnlRepayment" title="Repayment" data-options="href:'/Pages/AM/Repayment.aspx'" style="padding: 10px; width: auto; height: auto;">
        </div>
        <div id="pnlSecurity" title="Security" runat="server" data-options="href:'/Pages/AM/Security.aspx'" style="padding: 10px; width: auto; height: auto;">
        </div>
    </div>
    <script type="text/javascript">

        $(document).ready(function () {
            setHeight();
            fnLeftNavSelected('lnkSummary');
            
            $('#dgSummary').datagrid({
                onLoadSuccess: function (data) {
                    var rows = $('#dgSummary').datagrid('getRows');
                    if (rows.length > 0)
                        $('#dgSummary').datagrid('selectRow', 0);
                },
                onDblClickRow: function (index, rowdata) {
                    window.location.href = "/Pages/Contact/ContactDetail.aspx?contact_id=" + rowdata.ContactID;
                },
                onSelect: function (index, rowdata) {
                    $.ajax({
                        url: "/WebServices/ApplicationContact.ashx?method=ApplicationContactSelect",
                        contentType: "application/json; charset=utf-8",
                        data: { 'ContactID': rowdata.ContactID },
                        success: function (data) {
                            $.each(eval(data.replace(/[\r\n]/, '')), function (i, rec) {
                                $('#hdnContactId').val(rec.ContactID);
                                $('#hdnApp_Id').val(rec.app_id);
                                $('#txtTitle').val(rec.Title);
                                $('#txtName').val(rec.FirstName + ' ' + rec.MiddleName + ' ' + rec.SurName);
                                $('#txtFirstName').val(rec.FirstName);
                                $('#txtMiddleName').val(rec.MiddleName);
                                $('#txtSurName').val(rec.SurName);
                                $('#txtRole').val(rec.Role);
                                $('#txtRelationship').val(rec.Relationship);
                                $('#txtDOB').datebox('setValue', formatDateBirth(rec.DateBirth, null));
                                $('#txtMobilePhone').val(rec.Mobile);
                                $('#txtHomePhone').val(rec.HomePhone);
                                $('#txtWorkPhone').val(rec.WorkPhone);
                                $('#txtFaxNumber').val(rec.FaxNumber);
                                $('#txtEmail1').val(rec.Email);
                                $('#txtEmail2').val(rec.Email1);
                                $('#txtHomeAddress').val(rec.Street + ' ' + rec.Suburb + ' ' + rec.State + ' ' + rec.PostCode);
                                $('#txtStreet').val(rec.Street);
                                $('#txtSuburb').val(rec.Suburb);
                                $('#txtState').val(rec.State);
                                $('#txtPostCode').val(rec.PostCode);
                                $('#txtPostalAddress').val(rec.PostalAddress);
                                $('#txtIncomeType').combobox('setValue', rec.IncomeType);
                                $('#hdnIncomeType').val(rec.IncomeType);
                                $('#txtTypeofEntity').val(rec.SelfEmpTypeofEntity);
                                $('#txtBusinessName').val(rec.SelfEmpBusinessName);
                                $('#txtABN').val(rec.SelfEmpABN);
                                $('#txtNatureofBusiness').val(rec.SelfEmpNatureofBusiness);
                                $('#txtPhone').val(rec.SelfEmpPhone);
                                $('#txtAddress').val(rec.SelfEmpAddress);
                                $('#txtEmployer').val(rec.EmpEmployer);
                                $('#txtOccupation').val(rec.EmpOccupation);
                                $('#txtJobPosition').val(rec.EmpJobPosition);
                                $('#txtEmployerPhone').val(rec.EmpEmployerPhone);
                                $('#txtContactPerson').val(rec.EmpContactPerson);
                                $('#txtWorkAddress').val(rec.EmpWorkAddress);
                                $('#txtKinsName').val(rec.KinsName);
                                $('#txtKinsRelationship').val(rec.KinsRelationship);
                                $('#txtContactNumber').val(rec.KinsContactNumber);
                                $('#txtNotes').val(rec.Notes);
                                if (rec.IncomeType == 'Self Employed') {
                                    $('#employee').hide();
                                    $('#selfemployed').show();
                                }
                                else {
                                    $('#selfemployed').hide();
                                    $('#employee').show();
                                }
                            });
                        }
                    });
                }
            });
        });
        function getQuerystring(key, defaultValue) {
            if (defaultValue == null) defaultValue = "";
            key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
            var qs = regex.exec(window.location.href);
            if (qs == null)
                return defaultValue;
            else {
                return qs[1];
            }
        }
        
        function formatDateBirth(value, row) {
            if (value == null)
                return '';
            var date = new Date(value);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var month = '';
            switch (m) {
                case 1:
                    month = 'Jan';
                    break;
                case 2:
                    month = 'Feb';
                    break;
                case 3:
                    month = 'Mar';
                    break;
                case 4:
                    month = 'Apr';
                    break;
                case 5:
                    month = 'May';
                    break;
                case 6:
                    month = 'Jun';
                case 7:
                    month = 'Jul';
                    break;
                case 8:
                    month = 'Aug';
                    break;
                case 9:
                    month = 'Sep';
                    break;
                case 10:
                    month = 'Oct';
                    break;
                case 11:
                    month = 'Nov';
                    break;
                case 12:
                    month = 'Dec';
                    break;
            }
            var d = date.getDate();
            return (d < 10 ? ('0' + d) : d) + ' ' + month + ' ' + y;
        }

    </script>
</body>
</html>
